package com.ruoyi.common.core.page;

import java.io.Serializable;
import java.util.List;

/**
 * 分页数据对象（扩展版）
 */
public class PageDataInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 总记录数 */
    private long total;

    /** 当前页码 */
    private int pageNum;

    /** 每页大小 */
    private int pageSize;

    /** 总页数 */
    private int pages;

    /** 是否有下一页 */
    private boolean hasNextPage;

    /** 是否有上一页 */
    private boolean hasPreviousPage;

    /** 列表数据 */
    private List<?> rows;

    /** 消息状态码 */
    private int code;

    /** 消息内容 */
    private String msg;

    public PageDataInfo() {}

    public PageDataInfo(List<?> list, long total, int pageNum, int pageSize)
    {
        this.rows = list;
        this.total = total;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.pages = (int) Math.ceil((double) total / pageSize);
        this.hasNextPage = pageNum < pages;
        this.hasPreviousPage = pageNum > 1;
        this.code = 200;
        this.msg = "查询成功";
    }

    // getter 和 setter 方法
    public long getTotal() { return total; }
    public void setTotal(long total) { this.total = total; }

    public int getPageNum() { return pageNum; }
    public void setPageNum(int pageNum) { this.pageNum = pageNum; }

    public int getPageSize() { return pageSize; }
    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    public int getPages() { return pages; }
    public void setPages(int pages) { this.pages = pages; }

    public boolean isHasNextPage() { return hasNextPage; }
    public void setHasNextPage(boolean hasNextPage) { this.hasNextPage = hasNextPage; }

    public boolean isHasPreviousPage() { return hasPreviousPage; }
    public void setHasPreviousPage(boolean hasPreviousPage) { this.hasPreviousPage = hasPreviousPage; }

    public List<?> getRows() { return rows; }
    public void setRows(List<?> rows) { this.rows = rows; }

    public int getCode() { return code; }
    public void setCode(int code) { this.code = code; }

    public String getMsg() { return msg; }
    public void setMsg(String msg) { this.msg = msg; }
}
